<template>
	<view class="login">
		<view class="content">
			<!-- 头部logo -->
			<view class="header">
				<!-- <image :src="logoImage"></image> -->
			</view>
			<!-- 主体表单 -->
			<view class="main">
				<wInput v-model="phoneData" type="text" maxlength="17" placeholder="账号" :focus="isFocus"></wInput>
				<wInput v-model="passData" type="password" maxlength="11" placeholder="密码" isShowPass></wInput>
			</view>
			<wButton class="wbutton" text="登 录" :rotate="isRotate" @click="startLogin"></wButton>

			<!-- 其他登录 -->
			<view class="other_login cuIcon">
				<view class="login_icon">
					<view class="cuIcon-weixin" @tap="login_weixin"></view>
				</view>
				<!-- <view class="login_icon">
					<view class="cuIcon-weibo" @tap="login_weibo"></view>
				</view>
				<view class="login_icon">
					<view class="cuIcon-github" @tap="login_github"></view>
				</view> -->
			</view>

			<!-- 底部信息 -->
			<view class="footer">
				<!-- <navigator url="forget" open-type="navigate">找回密码</navigator>
				<text>|</text> -->
				<navigator url="register" @click="handleToregister">注册账号</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	let _this;
	import wInput from '../../components/watch-login/watch-input.vue' //input
	import wButton from '../../components/watch-login/watch-button.vue' //button
	export default {
		data() {
			return {
				//logo图片 base64
				// logoImage: ''
				phoneData: '', //用户/电话
				passData: '', //密码
				isRotate: false, //是否加载旋转
				isFocus: true // 是否聚焦
			};
		},
		components: {
			wInput,
			wButton,
		},
		mounted() {
			// this.getprofile()
			_this = this;
			//this.isLogin();
		},
		methods: {
			handleToregister() {
				uni.navigateTo({
					url: '../register/register'
				})
			},
			getprofile(){
				uni.$http.post('/user-server/api/user/v1/detail').then(res => {
					console.log(res)
					if (res.data.code === 200) {
						this.$store.commit('m_user/updateUserInfo', res.data.data)
						console.log(res)
					}
				})
			},
			
			// uni.request({
			// 	// url: 'http://192.168.1.111:8889/user-server/api/user/v1/detail',
			// 	url: 'http://yym2417581902.qicp.net/user-server/api/user/v1/detail',
			// 	method: 'POST',
			// 	header: {
			// 		token: this.$store.state.m_user.token
			// 	},
			// 	success(res) {
			// 		_this.$store.commit('m_user/updateUserInfo', res.data.data)
			// 		// console.log(res)
			// 	}
			// })
		// },
		isLogin() {

		},
		startLogin(e) {
			// console.log(e)
			//登录
			if (this.isRotate) {
				//判断是否加载中，避免重复点击请求
				return false;
			}
			if (this.phoneData.length == "") {
				uni.showToast({
					icon: 'none',
					position: 'bottom',
					title: '账号不能为空'
				});
				return;
			}
			if (this.passData.length < 5) {
				uni.showToast({
					icon: 'none',
					position: 'bottom',
					title: '密码不正确'
				});
				return;
			}
			if (this.phoneData && this.passData) {
				uni.$http.post('/user-server/api/user/v1/login', {
					"stuNo": this.phoneData,
					"pwd": this.passData
				}).then(res => {
					// console.log(res)
					if (res.data.code === 200) {
						this.$store.commit('m_user/updateToken', res.data.data)
						_this.isRotate = false
						this.getprofile()
						uni.navigateBack({
							
						})
						uni.$showMsg('登录成功')
					
						// console.log(res.data)
					} else {
						_this.isRotate = false
						uni.$showMsg('登录失败')
					}
				})
			}
			_this.isRotate = true
			// 1278956947@qq.com
		},

	}
	}
</script>

<style>
	@import url("../../components/watch-login/css/icon.css");
	@import url("./css/main.css");
</style>
